/**
 * *****************************************************************
 * @file    adt3102_spi.h
 * @author  WuHao(hwu@andartechs.com.cn)
 * @version 1.0.0
 * @date    2020-11-24
 * @brief   
 *                 Copyright (c) 2020, Andar Technologies Inc.
 *                           www.andartechs.com 
 *
 * *****************************************************************
 */
#ifndef __SPI_H
#define __SPI_H


/*------------------------------ include -------------------------------------*/
#include "adt3102_type_define.h"
#include "spi_ctype_map.h"


/*------------------------------ define --------------------------------------*/
#define SPI_MASTER_MODE 0
#define SPI_SLAVE_MODE  1


/*------------------------------ function ------------------------------------*/
/**
 * @brief   spiInit.
 * @param   SpiX: SPI0/SPI1.
 * @param   spiMode: .
 * @return  None.
 * @note
 */
void spiInit(SPI_TypeDef *SpiX, uint8 spiMode);

/**
 * @brief   manually set the cs signal of spi .
 *          spiCsSelect:high level     spiCsDeselect:low level
 * @param   SpiX: SPI0/SPI1.
 * @return  None.
 * @note
 */
void spiCsSelect(SPI_TypeDef *SpiX);
void spiCsDeselect(SPI_TypeDef *SpiX);

/**
 * @brief   spi write 1 byte data .
 * @param   SpiX: SPI0/SPI1.
 * @param   txData: tx data.
 * @return  None.
 * @note
 */
void spiWrite(SPI_TypeDef *SpiX,uint8 txData);

/**
 * @brief   spi read 1 byte data .
 * @param   SpiX: SPI0/SPI1.
 * @return  None.
 * @note
 */
uint8 spiRead(SPI_TypeDef *SpiX);

/**
 * @brief   spi batch write data.
 * @param   SpiX: SPI0/SPI1.
 * @param   pbuf: wirte data buf.
 * @param   len: .
 * @return  None.
 * @note
 */
void spiWriteBurst(SPI_TypeDef *SpiX,uint8 *pbuf,uint16 len);

/**
 * @brief   spi read burst.
 * @param   SpiX: SPI0/SPI1.
 * @param   pbuf: wirte data buf.
 * @param   len: .
 * @return  None.
 * @note
 */
void spiReadBurst(SPI_TypeDef *SpiX,uint8 *pbuf,uint16 len);

/**
 * @brief   SPI0 read write byte.
 * @param   SpiX: SPI0/SPI1.
 * @param   TxData: Need to send data.
 * @return  uint8.
 * @note
 */
uint8 spiReadWriteByte(SPI_TypeDef *SpiX,uint8 TxData);

/**
 * @brief   Waiting for the SPI transmission status to become idle status.
 * @param   SpiX: SPI0/SPI1.
 * @return  None.
 * @note
 */
void Wait_bsy(SPI_TypeDef *SpiX);

/**
 * @brief   flashPd.
 * @param   SpiX: SPI0/SPI1.
 * @return  None.
 * @note
 */
void flashPd(SPI_TypeDef *SpiX);

/**
 * @brief   flash release pd.
 * @param   SpiX: SPI0/SPI1.
 * @return  None.
 * @note
 */
void flashReleasePd(SPI_TypeDef *SpiX);

#endif
